<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>导入数据</title>
</head>
<body>
<input type="button" value="下载模板" onclick="downloadExcel()">
<input type="file" id="file" accept=".xlsx">
<input type="button" onclick="importExcel()" value="上传">
<div id="hide" style="display: none">
    上传成功
</div>
</body>
<script th:src="@{/js/libs/jquery.js}" type="text/javascript"></script>
<script>
    function downloadExcel() {
        window.location.href = "/js/common/用户导入模板.xlsx"
    }
    function importExcel() {
        var file = $("#file")[0].files[0]
        var data = new FormData()
        if(file == null){
            alert("未选择文件")
            return
        }
        data.append("file",file)
        $.ajax({
            url: "/excel/importExcel",
            data: data,
            type: "post",
            //不处理发送的数据
            processData: false,
            //不设置content-type请求头
            contentType: false,
            success: function () {
                $("#hide").show()
            }
        })
    }

</script>
</html>
